package com.yyx.server.controller;


import com.yyx.server.pojo.Salary;
import com.yyx.server.service.SalaryService;
import com.yyx.server.vo.ResultVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YongXin
 * @since 2021-07-24
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {

    @Autowired
    private SalaryService salaryService;

    @ApiOperation("获取所有工资账套")
    @GetMapping("/")
    public List<Salary> getAllSalaries(){
        return salaryService.list();
    }
    @ApiOperation("添加工资账套")
    @PostMapping("/")
    public ResultVo addSalary(@RequestBody Salary salary){
        if (salaryService.save(salary)){
            return ResultVo.success("添加成功");
        }
        return ResultVo.error("添加失败");
    }
    @ApiOperation("删除工资账套")
    @DeleteMapping("/{id}")
    public ResultVo delSalary(@PathVariable Integer id){
        if (salaryService.removeById(id)){
            return ResultVo.success("删除成功");
        }
        return ResultVo.error("删除失败");
    }
    @ApiOperation("更新工资账套")
    @PutMapping("/")
    public ResultVo updSalary(@RequestBody Salary salary){
        if (salaryService.updateById(salary)){
            return ResultVo.success("更新成功");
        }
        return ResultVo.error("更新失败");
    }
}

